<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

/**
 * Ajax action to delete a temporary page (table f_temp)
 * 
 * Called by undoModifs in jQueryBackend
 * 
 * @example module=backoffice&action=AjaxDeleteTempPage&pageId=12
 */
class m_website_actions_AjaxDeleteTempPageAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$pageId = $this->getRequestParameter("pageId");
		$pageLang = $this->getRequestParameter("pageLang");
		
		$tempDocService = m_backoffice_services_TempDocService::getInstance();
		
		$page = $tempDocService->getTemporaryDocument($pageId, $pageLang);
		
		$blocks = $page->getAllBlocks();
		
		$docProvider = f_document_Provider::getInstance();
		
		foreach($blocks as $block)
		{
			if(isset($block["contentId"]) && $block["contentId"] != null)
			{
				$tempDocService->deleteTempDocument($block["contentId"], $pageLang);
			}
		}
		
		$tempDocService->deleteTempDocument($pageId, $pageLang);
	}
}